<template>
  <div class="login-container">
    <div class="login-card">
      <h1 class="login-title">用户登录</h1>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input
              v-model="form.username"
              placeholder="请输入用户名"
              prefix-icon="el-icon-user"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
              v-model="form.password"
              type="password"
              placeholder="请输入密码"
              prefix-icon="el-icon-lock"
              show-password
          ></el-input>
        </el-form-item>
        <el-form-item class="forget-password">
          <el-link type="primary" @click="handleForget">忘记密码？</el-link>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-btn" @click="onLogin">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
//导入api
import {login} from "@/api/user"
export default {
  name: 'LoginView',
  data() {
    return {
      form: {
        username: '',
        password: '',
      },
    };
  },
  methods: {
    onLogin() {
      console.log('发送登录前信息', this.form);
      login(this.form).then(res => {
        console.log('发送登录后信息', res);
        if (res.code !== 200) {
          // 登录成功，保存用户信息到本地存储
          this.$message.error("用户名或密码错误");
        }else{
          this.$message.success("登录成功");
          this.$store.commit("setUserInfo",res.data);
          this.$router.push('/admin');
        }

      })

    },
    handleForget() {
      // 可添加“忘记密码”逻辑，如跳转页面
      console.log('点击忘记密码');
    },
  },
};
</script>

<style scoped>
/* 页面整体背景 */
.login-container {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #0a2b5c, #1f5aa8);
  background-image: url('https://picsum.photos/1920/1080'); /* 示例背景图，可替换为自己的 */
  background-size: cover;
  background-position: center;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 登录卡片容器 */
.login-card {
  width: 400px;
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* 登录标题 */
.login-title {
  text-align: center;
  margin-bottom: 30px;
  color: #0a2b5c;
  font-size: 24px;
  font-weight: 600;
}

/* 输入框样式（利用 Element UI 自带类名微调） */
.el-input {
  width: 100%;
}
.el-input__inner {
  border-radius: 6px;
  border-color: #c0d0e5;
  transition: all 0.3s ease;
}
.el-input__inner:focus {
  border-color: #1f5aa8;
  box-shadow: 0 0 0 2px rgba(31, 90, 168, 0.2);
}

/* 忘记密码链接 */
.forget-password {
  text-align: right;
  margin-bottom: 20px;
}

/* 登录按钮 */
.login-btn {
  width: 100%;
  border-radius: 6px;
  background-color: #1f5aa8;
  border-color: #1f5aa8;
  transition: all 0.3s ease;
}
.login-btn:hover {
  background-color: #0a2b5c;
  border-color: #0a2b5c;
}
</style>